package cn.edu.ujn.park.service;

import cn.edu.ujn.park.dao.User;
import cn.edu.ujn.park.dao.Vehicle;
import cn.edu.ujn.park.dao.VehicleMapper;
import cn.edu.ujn.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VehicleServiceImpl implements IVehicleService {
    @Autowired
    private VehicleMapper vehicleMapper;
    @Override
    public void insert(Vehicle vehicle) {
         vehicleMapper.insert(vehicle);
    }

    @Override
    public void updateByPrimaryKey(Vehicle vehicle) {
           vehicleMapper.updateByPrimaryKey(vehicle);
    }

    @Override
    public void deleteByPrimaryKey(Integer vehicleId) {
             vehicleMapper.deleteByPrimaryKey(vehicleId);
    }

    @Override
    public Vehicle getVehicleById(Integer vehicleId) {
        return vehicleMapper.selectByPrimaryKey(vehicleId);
    }

    @Override
    public Page<Vehicle> selectAll(Vehicle vehicle) {
        Page<Vehicle> page = new Page<>();
        List<Vehicle> list = vehicleMapper.selectAll(vehicle);
        Integer count=vehicleMapper.selectCount(vehicle);
        page.setPage(vehicle.getStart());
        page.setRows(list);
        page.setSize(vehicle.getRows());
        page.setTotal(count);
        return page;
    }

    @Override
    public String selectVehicleName(Integer vehicleId) {
        return vehicleMapper.selectVehicleName(vehicleId);
    }
}
